package com.haibei.adapter.bean;

import android.app.Activity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.common.bean.IBeanInterface;
import com.common.uitl.LogUtil;
import com.haibei.App;
import com.haibei.R;
import com.haibei.activity.MainActivity;
import com.haibei.view.AsnycImageView;

public class MenuItem implements IBeanInterface {

	private ArticleCategory mArticleCategory;
	private MainActivity mActivity;
	private View contnetView;

	private View mViewRect;
	private AsnycImageView imageViewIcon;
	private ImageView imageViewArrowRight;
	private TextView mTextViewTitle;

	public MenuItem(Activity activity, ArticleCategory category) {
		this.mArticleCategory = category;
		this.mActivity = (MainActivity) activity;
		contnetView = View.inflate(activity, R.layout.item_menu_category, null);
		mViewRect = contnetView.findViewById(R.id.viewRect);
		imageViewIcon = (AsnycImageView) contnetView.findViewById(R.id.imageViewIcon);
		imageViewIcon.setmDefaultDrable(activity.getResources().getDrawable(R.drawable.icon_health));
		mTextViewTitle = (TextView) contnetView.findViewById(R.id.textViewTitle);
		mTextViewTitle.setText(category.getName());
		imageViewArrowRight = (ImageView) contnetView.findViewById(R.id.imageViewArrowRight);
		unCheck();
	}

	public void check(ArticleCategory acategory) {
		if (mArticleCategory.isDefault()) {
			imageViewIcon.setmDefaultDrable(mActivity.getResources().getDrawable(mArticleCategory.getIntIconSelected()));
			LogUtil.i(App.tag, "tagmesg:" + mActivity.toString());
			mActivity.showContent();
		} else {
			String url = mArticleCategory.getIconSelected();
			imageViewIcon.setUrl(url);
		}
		mTextViewTitle.setTextColor(mActivity.getResources().getColor(R.color.text_color_green));
		mViewRect.setBackgroundResource(R.drawable.icon_rect_p);
		imageViewArrowRight.setBackgroundResource(R.drawable.icon_arrow_right_p);
	}

	public void unCheck() {
		mViewRect.setBackgroundDrawable(null);
		if (mArticleCategory.isDefault()) {
			imageViewIcon.setmDefaultDrable(mActivity.getResources().getDrawable(mArticleCategory.getIntIconDefault()));
			imageViewIcon.invalidate();
		} else {
			String url = mArticleCategory.getIconDefault();
			imageViewIcon.setUrl(url);
		}
		mTextViewTitle.setTextColor(mActivity.getResources().getColor(R.color.text_color_dark));
		imageViewArrowRight.setBackgroundResource(R.drawable.icon_arrow_right);
	}

	public View getView() {
		contnetView.setTag(this);
		return contnetView;
	}

	public ArticleCategory getmArticleCategory() {
		return mArticleCategory;
	}

	public void setmArticleCategory(ArticleCategory mArticleCategory) {
		this.mArticleCategory = mArticleCategory;
	}

}
